package com.sunxueqi.project.log.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunxueqi.common.constant.StatusConstants;
import com.sunxueqi.common.utils.SecurityUtils;
import com.sunxueqi.project.log.dao.VisitLogMapper;
import com.sunxueqi.project.log.service.IVisitLogService;
import com.sunxueqi.project.log.vo.VisitLog;

@Service
public class VisitLogServiceImpl implements IVisitLogService{
	
	@Autowired
	private VisitLogMapper visitLogMapper;
	
	@Override
	public List<VisitLog> selectVisitLogList(VisitLog visitLog) {
		visitLog.setDeleteStatus(StatusConstants.NORMAL);
		return visitLogMapper.selectList(visitLog);
	}

	@Override
	public int deleteVisitLogByIds(String[] idArray) {
		int result = 0;
		for(String id: idArray) {
			VisitLog visitLog = new VisitLog();
			visitLog.setId(id);
			visitLog.setDeleteStatus(StatusConstants.DELETED);
			visitLog.setDeleteTime(new Timestamp(System.currentTimeMillis()));
			visitLog.setDeleteBy(SecurityUtils.getLoginUserId());
			int count = visitLogMapper.updateByPrimaryKey(visitLog);
			result += count;
		}
		return result;
	}
	
	@Override
	public void cleanLog() {
		visitLogMapper.cleanLog(SecurityUtils.getLoginUserId(), StatusConstants.DELETED, StatusConstants.NORMAL);
	}

	@Override
	public int insertVisitLog(VisitLog visitLog) {
		return visitLogMapper.insert(visitLog);
	}
}
